﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: CMS管理 登陆页
//最后修改: 2010-10-11
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TRPOP.CMS.Web.UI;


using TRPOP.Common;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Web.Admin
{
    /// <summary>
    /// 登陆
    /// </summary>
    public partial class Login : BaseAdmin
    {
        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.CheckifLogin())
                base.Redirect("Admin_Index.aspx");
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strMSG = "用户名、密码或验证码";
            if (!PageAssist.CheckForm(txtUserName, ref strMSG) || !PageAssist.CheckForm(Secode, ref strMSG))
            {
                AlertDialog(strMSG);
                return;
            }
            string strUserName, strPassWord, strSecode;
            strUserName = txtUserName.Text.Trim().SQLFilter();
            strPassWord = txtPassWord.TextTrim.SQLFilter();
            strSecode = Secode.Text.Trim();
            if (Session["CheckCode"] == null)
            {
                //ErrorInfo.Text = "你可能长时间未进行操作，请重新输入验证码！";
                AlertDialog("你可能长时间未进行操作，请重新输入验证码！");
                return;
            }
            if (Session["CheckCode"].ToString().ToLower() != strSecode.ToLower())
            {
                //ErrorInfo.Text = "验证码错误！";
                AlertDialog("验证码错误！");
                return;
            }
            else
            {
                if (base.AdminUserLogin(strUserName, strPassWord))
                {
                    base.SaveLog(Plugin.LogKeys.OperObject.SysLogin,Plugin.LogKeys.OperResult.Success);
                    if (TRPOP.Common.RequestHelper.GetUrlReferrer().ToLower().Contains("login.aspx") == false)
                        base.Redirect(TRPOP.Common.RequestHelper.GetUrlReferrer());
                    else
                        base.Redirect(SystemConst.SystemAdminIndexPage);

                }
            }
            //ErrorInfo.Text = "用户名或密码错误!";
            AlertDialog("用户名或密码错误！");
            base.SaveLog(Plugin.LogKeys.OperObject.SysLogin, Plugin.LogKeys.OperResult.Failed);
        }

        #endregion
    }
}
